package IntToChar;

import java.util.Scanner;

import java.math.BigDecimal;

public class MoneyChange {


    public static void main(String[] args) {
        String capNumber[] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};     //capNumber[]存储大写数字汉字
        String unit[] = {"","圆","拾","佰","仟","万","拾","佰","仟","亿","拾","佰","仟"}; //unit[]存储每一个位数所对应的大写汉字单位  unit[0]="",方便对应。

        System.out.println("请输入12位以内的任意整数：");
        Scanner sc=new Scanner(System.in);
        long num;
        String line;
        String integerStr;// 整数部分数字
        String decimalStr;// 小数部分数字
        //判断输入数字的合理性
        while (true)
        {
            num=sc.nextLong();
            line=num+"";
            if (line.length()>12)
                System.out.println("您输入的数据位数过大！请重新输入：");
            else
                break;
        }
        if (line.indexOf(".")>0)
        {
            integerStr = line.substring(0, line.indexOf("."));
            decimalStr = line.substring(line.indexOf(".") + 1);
        }
        else if (line.indexOf(".")==0)
        {
            integerStr = "";
            decimalStr = line.substring(1);
        }
        else {
            integerStr = line;
            decimalStr = "";
        }
       /* int integers = integerStr;// 整数部分数字
        boolean isMust5 = isMust5(integerStr);// 设置万单位
        int decimals = toArray(decimalStr);// 小数部分数字*/
        int times=0;    //记录除数的次数
        long quotient=0;    //记录每一次的商
        long remainder=0;    //记录每一次的余数
        String str="";
        while (true)
        {
            quotient=num/10;
            remainder=num%10;
            if (quotient==0&&remainder==0)
            {
                break;
            }
            else
                num=quotient;
            times++;
            str =  capNumber[ (int) remainder]+unit[times] + str;
        }
        str = str.replaceAll("零[拾佰仟]","零").replaceAll("零+亿","亿").replaceAll("零{4}万", "")
                .replaceAll("零+万","万").replaceAll("零+圆","圆").replaceAll("零+", "零")+"整";
        System.out.println("阿拉伯数字转换成中国传统形式为: ");
        System.out.println(str);                            //输出字符串

    }
}
